var api = require('../../utils/api.js')

Page({
    data: {
        list: [],
        nickname:'',
        ispz:0
    },
    onLoad() {

    },
    onShow() {
        var that=this;

        wx.login({
            success: function (ret) {
                console.log(ret);
                wx.getUserInfo({
                    success: function () {
                        api.post({
                            url: 'wxapp/getopenid',
                            data: {'code':ret.code},
                            success: data => {
                                that.setData({
                                    userinfo:data.data.userinfo,
                                    token:data.data.userinfo.token
                                })

                                wx.setStorageSync('token', data.data.userinfo.token)
                                wx.setStorageSync('userinfo', data.data.userinfo)

                            }
                        })
                    }
                })
            }
        })

        api.post({
            url: 'user/index',
            data: {},
            success: data => {
                that.setData({
                    avatar:data.data.avatar,
                    nickname:data.data.nickname,
                    ispz:data.data.ispz
                })
            }
        })

  

    },

    setwork(){
        var ph=this.data.ispz;
        if(ph==1){
            wx.navigateTo({
                url: '/pages/work/home',
            })
        }else{
            wx.navigateTo({
                url: '/pages/work/index',
            })
        }
    },

    seeuser(){
        wx.navigateTo({
            url: '/pages/my/fuwu',
        })
    },
    myset(){
        wx.navigateTo({
            url: '/pages/my/set',
        })
    },

    setorder(ret){
        console.log(ret);

        var i=ret.currentTarget.dataset.i;

 
        wx.navigateTo({
            url: '/pages/order/index?status='+i
        })
    },

    getqrcode(){
       

    },
    zhifu(){

        api.get({
            url: 'wxpay/pays',
            data: {},
            success: data => {
                if(data.code!=1){
                    wx.showToast({
                      title: data.msg,icon:'none'
                    })

                    return false;
                }
                wx.requestPayment({
                    timeStamp:data.data.timeStamp,
                    nonceStr: data.data.nonceStr,
                    package: data.data.package,
                    signType: 'MD5',
                    paySign: data.data.paySign,
                    success (res) {
                        wx.reLaunch({
                            url: '/pages/myorder/index',
                          })
                     },
                    fail (res) {
                        console.log('error',res)
                        wx.reLaunch({
                            url: '/pages/myorder/index',
                          })
                     }
                })

            }
        });

    },
    callphone(){
        wx.makePhoneCall({
          phoneNumber: '13556229392',
        })
    }
});